package com.yinhai.app.demo.controller;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.ModelAndView;

import com.yinhai.app.demo.service.DemoService;
import com.yinhai.common.controller.BaseController;
@SuppressWarnings({ "unchecked", "rawtypes" })
@Controller
@RequestMapping(value = "/app/site")
public class DemoController extends BaseController {
	@Autowired
	@Qualifier("demoService")
	private DemoService demoService;
	
	@RequestMapping(value="/demo", method = {RequestMethod.GET})
	public ModelAndView test() throws Exception {
		ModelAndView modelAndView = new ModelAndView();
		List list = demoService.queryList(null);
		modelAndView.addObject("list", list); 
		modelAndView.setViewName("/demo/list"); 
		return modelAndView;
	}
	
	@RequestMapping(value="/hello", method = {RequestMethod.GET})
	public ModelAndView hello() throws Exception {
		ModelAndView modelAndView = new ModelAndView();
		modelAndView.setViewName("/demo/hello"); 
		return modelAndView;
	}
	@RequestMapping(value="/save", method = {RequestMethod.GET})
	public Map saveTest() throws Exception {
		Map map = new HashMap();
		map.put("error", false);
		map.put("name", "yuan");
		map.put("age", 26);
		demoService.insertDemo(map);
		return map;
	}
}
